#!/bin/bash

for ((i = 1; i <= $1; i++)) ; do
	echo $i
	n=$((RANDOM%5))
	if [ $n -eq 0 -o $n -eq 1 ]; then
		echo 'Ta = 5s'
		sleep 5
		./client client_$i &
	elif [ $n -eq 2 -o $n -eq 3 ]; then
		echo 'Ta = 2s'
		sleep 2
		./client client_$i &
	else
		echo 'BURST!!!!'
		x=$(($1 - $i))
		if (($x < 5 )); then
			if [ $x -eq 0 ]; then
				./client client_$1
			else
				for ((j = 0; j < $x; j++)); do
					./client client_$((i+j)) &
				done
				i=$(($1))
			fi
		else
			for ((j = 0; j < 5; j++)); do
				./client client_$((i+j)) &
			done
			i=$(($i+4))
		fi	
	fi
done